import { createClientTokenAuthentication } from '@alova/scene-vue';
import { getToken, setToken } from '@/hooks/auth.js';

// 全局Token认证拦截器
export const { onAuthRequired, onResponseRefreshToken } =
  createClientTokenAuthentication({
    refreshToken: {
      // 在请求前触发，将接收到method参数，并返回boolean表示token是否过期
      isExpired: (method) => {
        return !getToken();
      },
    },
    assignToken: (method) => {
      method.config.headers.token = getToken();
    },
  });
